// --------------------------------------------------------------------------------------------------------------------
// <copyright file="MainWindow.xaml.cs" company="Akzente.IT">
//   (c) 2012 Akzente.IT
// </copyright>
// <summary>
//   Interaction logic for MainWindow.xaml
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace AkzenteIT.DatabaseDocumentationTool.Views
{
    using System.Windows;
    using System.Windows.Data;

    using AkzenteIT.DatabaseDocumentationTool.ViewModels;
    using AkzenteIT.DatabaseDocumentationTool.ViewModels.Base;

    using Microsoft.SqlServer.Management.Common;
    using Microsoft.SqlServer.Management.Smo;

    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow
    {
        #region Fields

        /// <summary>
        /// The view model.
        /// </summary>
        private readonly MainWindowViewModel viewModel;

        #endregion

        #region Constructors and Destructors

        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindow"/> class.
        /// </summary>
        public MainWindow()
        {
            this.InitializeComponent();

            ServerConnection connection = new ServerConnection("(local)");

            Server server = new Server(connection);

            var serverViewModel = new ServerViewModel(server);

            this.viewModel = new MainWindowViewModel();
            this.viewModel.Servers.Add(serverViewModel);

            this.DataContext = this.viewModel;
        }

        #endregion

        #region Methods

        /// <summary>
        /// The collection view source_ filter.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void CollectionViewSourceFilter(object sender, FilterEventArgs e)
        {
            e.Accepted = e.Item is IDbObjectViewModel;
        }

        /// <summary>
        /// The database tree_ selected item changed.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void DatabaseTreeSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            this.viewModel.SelectedNode = this.databaseTree.SelectedItem as NodeViewModel;
        }

        #endregion
    }
}